package com.aierjun.ani.net.OkGo.okupload;

import android.util.Log;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.util.Arrays;
import java.util.List;

/**
 * Created by Ani_aierJun on 2017/10/16.
 */

public class UploadEntityListSerializable {


        /**
         * 序列化,List
         */
        public static <T> boolean writeObject(List<T> list, File file)
        {
            T[] array = (T[]) list.toArray();
            try {
                ObjectOutputStream outputStream = new ObjectOutputStream(new FileOutputStream(file));
                outputStream.writeObject(array);
                outputStream.flush();
                return true;
            }
            catch (IOException e)
            {
                e.printStackTrace();
                return false;
            }
        }

        /**
         * 反序列化,List
         */
        public static <E> List<E> readObjectForList(File file)
        {
            try
            {
                ObjectInputStream out = new ObjectInputStream(new FileInputStream(file));
                E[] object = (E[]) out.readObject();
                return Arrays.asList(object);
            }
            catch (IOException e)
            {
//                e.printStackTrace();
                Log.d("Jun", "..........");
            }
            catch (ClassNotFoundException e)
            {
//                e.printStackTrace();
                Log.d("Jun","ClassNotFoundException");
            }
            return null;
        }



}
